const app = getApp()
Page({
  data: {
    uid:0,
    isManage:false,
    isvip: false,
    bank: {
      money: 0,
      lack_money: 0,
      save_money: 0,
      income_money: 0,
      shop_money: 0
    },
    order:[0,0],
    config: [],
  },
  //监听页面初次载入完成
  onLoad: function (options) {
    app.getParam(options,(rel) => {
      if (!app.util().isNull(rel.ucode)) {
        wx.switchTab({
          url:'../card/vip'
        })
      }
    });
  },
  //生命周期函数--监听页面显示
  onShow: function () {
    this.setData({
      ucode:app.util().isNull(app.globalData.loginuser.ucode) ? '': app.globalData.loginuser.ucode,
      uid:app.util().isNull(app.globalData.loginuser) ? 0: app.globalData.loginuser.uid,
    })
    this.getApi(); 
  },
  //生命周期函数--监听页面准备好
  onReady: function () {
    this.setData({
      config: app.globalData.appConfig
    })
  },
  //判断是否开通城市号
  isMp:function () {
    var param = {
      signkey:app.util().getRandom(12)
    }
    app.api().Get('api/v4/allwin/infosend/isRegMp',param,(result)=>{
      if(result.code == 200){
        wx.navigateTo({
          url: '../info/me?uid='+this.data.uid,
        })
      }else{
        wx.showModal({
          content: '你还未开通城市号,请先开通!',
          cancelText:'取消',confirmText	:'去开通',
          success:(res)=>{
            if (res.confirm) {
              wx.navigateTo({
                url: '../info/edit',
              })
            }
          }
        })
      }
    })
  },
  //读取我的订单
  getApi: function() {
    if (this.data.uid > 0){
      //获取余额
      var param = {
        'signkey': app.util().getRandom(12)
      }
      app.api().Get("api/v4/allwin/bank/index", param,(result) => {
        if (result.code == 200) {
          this.setData({
            bank: result.data
          });
        }
      })
      //活动订单数量
      var count = {
        'signkey': app.util().getRandom(12)
      }
      app.api().Get("api/v4/allwin/shoporder/count", count,(result) => {
        if (result.code == 200) {
          this.setData({
            order: result.data
          });
        }
      })
    }
  },
  //拨打电话
  callPhone:function (e) {
    app.callPhone(e);
  },
  //进入钱包
  onMonay: function () {
    wx.navigateTo({
      url: '../money/index',
    })
  },
  //进入会员
  linkVip: function () {
    wx.switchTab({
      url: '../card/vip',
    })
  },
  //一键复制事件
  copyBtn: function () {
    wx.setClipboardData({
      data: '开通会员填写我的邀请码【 ' + app.globalData.loginuser.ucode +' 】和我一起省钱,还能赚钱.',
      success:(res) =>{
        wx.showToast({
          title: '复制成功',
        });
      }
    });
  },
  //分享按钮
  onShareAppMessage: function (res) {
    return {
      title: '我在【' + app.appname + '】已获得收益 ￥' + this.data.bank.income_money + ' 元,加入我一起.',
      path: '/pages/index?ucode=' + app.globalData.loginuser.ucode
    }
  }
})